<?php
session_start();
$pfadTiefe = str_replace($_SERVER['DOCUMENT_ROOT'], "", dirname(__FILE__)."/" ); // alle nötigen PHP funktionen einfügen
$slashCount = substr_count($pfadTiefe, '/'); // Zählen wieviele Slashes drinne sind
$ebeneTiefer = "";
for($i=0; $i<$slashCount; $i++){ // für jeden slash eine ebene tiefergehen
	$ebeneTiefer .= DIRECTORY_SEPARATOR . '..';
}
$pfad = dirname(__FILE__).$ebeneTiefer;
require_once($pfad."/inc/inc_general_php_functions.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Profile page of <?php echo $_SESSION['user']['name'];?> with specific data about his account on Dota2 League">
<meta name="robots" content="index,follow">
<title>Dota2 League - Profile of <?php echo $_SESSION['user']['name'];?></title>
<?php
	require_once(DR.HOME_PATH_REL."/inc/inc_css_and_js.php");
?>

<?php
	$id = $_GET['ID'];
	if($id > 0){
		$steamID = $id;
	}
	else{
		$steamID = $_SESSION['user']['steamID'];
	}

	$_SESSION['tmp']['steamID'] = $steamID; // an ajax übergeben

	$MatchDetails = new MatchDetails();
	$User = new User();
	$UserStats = new UserStats();
	$MatchMode = new MatchMode();
	$MatchType = new MatchType();
	// User Details
	$userData = $User->getUserData($steamID);

	$userStats = $UserStats->getUserStats($steamID);

	// last 5 Matches
	$last5Matches = $MatchDetails->getLastMatchDetailsOfPlayer($steamID, 5, "DESC");

	// best Results auslesen
	$Ladder = new Ladder();
	$bestRankings = $Ladder->getBestRankings($steamID, 5);

	// general ranking
	$generalRanking = $Ladder->getGeneralRanking($steamID, $userStats['Rank']);

	// get Notifications
	//$Profile = new Profile();
	//$notificationData = $Profile->getNotifications($steamID);

	// get All Matchmodes
	$matchmodes = $MatchMode->getAllMatchModes();
	
	// get all Matchtypes
	$matchtypes = $MatchType->getAllMatchTypes();
	
	// User Credits auslesen
	$UserCredits = new UserCredits();
	$retCredits = $UserCredits->getCreditCountOfPlayer($steamID);
	
	// Assign Smarty Variables
	$smarty->assign('steamID', $steamID);
	$smarty->assign('userData', $userData);
	$smarty->assign('userStats', $userStats['data']);
	$smarty->assign('last5Matches', $last5Matches['data']);
	$smarty->assign('bestRankings', $bestRankings['data']);
// 	$smarty->assign('notificationData', $notificationData['data']);
// 	$smarty->assign('notificationCount', $notificationData['count']);
	$smarty->assign('ranking', $generalRanking['position']);
	$smarty->assign('matchmodes', $matchmodes);
	$smarty->assign('matchtypes', $matchtypes);
	$smarty->assign('userCredits', $retCredits['data']);
	
	// Debug
	$_SESSION['debug'] = "";
//	$_SESSION['debug'] .= p($notificationData,1);
// 	$_SESSION['debug'] .= p($bestRankings,1);
// 	$_SESSION['debug'] .= p($userStats,1);
 	$_SESSION['debug'] .= p($userData,1);
// 	$_SESSION['debug'] .= p($last5Matches,1);
?>
</head>

<body>
  <div id="wrap">
   <?php
	 			$smarty->display('top_navi.tpl');
			?>
      <div class="container">
      	<?php
	 			$smarty->display('profile/index.tpl');
		?>
		</div> <!-- /container -->
    </div>
    <div id="footer">
      <div class="container">
        <?php $smarty->display('footer.tpl'); ?>
      </div>
    </div>
    <?php $smarty->display('general_stuff.tpl');?>
</body>
</html>